var scene,
    camera,
    renderer;

//场景初始化

function init(){
    scene=new THREE.Scene(); //初始化场景

    // 透视相机 远近高低各不同

    camera=new THREE.PerspectiveCamera(
        90,
        document.body.clientWidth/document.body.clientHeight,
        0.1, // 最近拍摄距离
        100 //最远拍摄距离
        );

    camera.position.set(0,0,3);  //z轴，1表示半个距离
    renderer=new THREE.WebGLRenderer({
        antialias:true    //优化，抗锯齿
    });  //openGL在web的实现，用于 3d 图形 计算机图形学
    renderer.setSize(
        document.body.clientWidth,
        document.body.clientHeight
    )
    document
        .getElementById("container")
        .appendChild(renderer.domElement);
        var controls=new THREE.OrbitControls(camera,renderer.domElement);
        loadCarmModal();
        loop();
        addlight();
}
function loop(){
    // 申请显卡的显示频率
    requestAnimationFrame(loop);
    renderer.render(scene, camera);
}
function loadCarmModal(){
        //1oom 加一个loader.js
        const loader=new THREE.GLTFLoader();
        loader.load(
            './images/model.gltf',
            function(gltf){
                //成功加载后
                scene.add(gltf.scene);
            },
            function(xhr){
                //加载中
                console.log((xhr.loaded/xhr.total * 100)+'% loding');
            },
            function(error){
                //加载失败
                console.log('an error happened');
            }
        )
}
function addlight(){
    var ambientLight=new THREE.AmbientLight(0xd5d5d5);
    ambientLight.intensity=1.2;
    scene.add(ambientLight);
}
window.onload=init; //资源加载之后运行
